/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.colswe.solestac.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Table;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Column;
import javax.persistence.Basic;
import javax.persistence.OneToMany;
import javax.persistence.ManyToMany;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Julian Peña
 * @version 1.0
 */
@Entity
@Table(name = "rol")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Rol.findAll", query = "SELECT r FROM Rol r"),
    @NamedQuery(name = "Rol.findById", query = "SELECT r FROM Rol r WHERE r.id = :id"),
    @NamedQuery(name = "Rol.findByName", query = "SELECT r FROM Rol r WHERE r.name = :name") })
public class Rol implements Serializable {
    /**List of users with the role.
     */
    @OneToMany(mappedBy = "rol")
    private List<FinalUser> finalUserList;
    /**Version of the Serializable interface.
     */
    private static final long serialVersionUID = 1L;
    /**Id from the role.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    /**Name from the role.
     */
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    /**List of perrmisison associated to the role.
     */
    @ManyToMany(mappedBy = "rolList")
    private List<Permission> permissionList;
    
    /**Default constructor.
     */
    public Rol() {
    }

    /**Constructur using the Id.
     * @param newId The new value
     */
    public Rol(final Long newId) {
        this.id = newId;
    }

    /**Constructor using the Id and Name.
     * @param newId The new value
     * @param newName The new value
     */
    public Rol(final Long newId, final String newName) {
        this.id = newId;
        this.name = newName;
    }

    /**Getter for Id.
     * @return The Id value
     */
    public Long getId() {
        return id;
    }

    /**Setter for Id.
     * @param newId Tne new value. 
     */
    public void setId(final Long newId) {
        this.id = newId;
    }

    /**Getter for Name.
     * @return The Name value.
     */
    public String getName() {
        return name;
    }

    /**Setter for Name.
     * @param newName The new value
     */
    public void setName(final String newName) {
        this.name = newName;
    }

    /**Assignment of the hashcode.
     * @return The hash
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    /**Convert to string using the Id.
     * @return The string
     */
    @Override
    public String toString() {
        return "org.colswe.solestac.entity.Rol[ id=" + id + " ]";
    }

    /**Getter for Permissions.
     * @return The permissions list.
     */
    @XmlTransient
    public List<Permission> getPermissionList() {
        return permissionList;
    }

    /**Setter for Permissions.
     * @param newPermissionList The new Permissions.
     */
    public void setPermissionList(final List<Permission> newPermissionList) {
        this.permissionList = newPermissionList;
    }

    /**Getter for the Users List.
     * @return The FinalUsers list
     */
    public List<FinalUser> getFinalUserList() {
        return finalUserList;
    }

    /**Setter for the Users List.
     * @param newFinalUserList The nwe FinalUser list
     */
    public void setFinalUserList(final List<FinalUser> newFinalUserList) {
        this.finalUserList = newFinalUserList;
    }

}
